html(lang="en")
    head
        meta(charset="UTF-8")
        meta(name="viewport", content="width=device-width, initial-scale=1.0")
        meta(http-equiv="X-UA-Compatible", content="ie=edge")
        link(rel="stylesheet", href="css/style.css")
        script(src="js/jquery.min.js")
        title 主页
    body
        include ./components/header.jade
        div(id='selectDiv')
           img(src='img/'+posts[0].author.avatar,class='select_img_content')
        div#menuContainer
            div.one
            div.two
            div.menuSty
                div.menu-item(style={'border-bottom':'1px solid #ccc'}) 登出
                div.menu-item 发布
        ul
           -for(let i=0;i<posts.length;i++)  
                div(class="value-pass",style={display: 'none'})= posts[i].content
                li.item
                    div(style={'width':'100%','height':'40px'})
                        div.item-img
                            img(src='img/'+posts[i].author.avatar)
                        span.item-name=posts[i].author.name
                        span.item-time=posts[i].time
                    div.item-title= posts[i].title
                    a(href="http://localhost:3000/posts/"+posts[i]._id)
                        div.item-content 
                    div.item-icons
                        a(href="http://localhost:3000/posts/"+posts[i]._id+"/edit")
                            span(class='item-icon-edit') 编辑
                        a(href="http://localhost:3000/posts/"+posts[i]._id+"/remove")
                            span(class='item-icon-del') 删除
               
        script.
            $('#selectDiv').click(function(){
                $('#menuContainer').css('display','block')
            });



            $(document).ready(function(){
                
                $('#menuContainer').mouseleave(function(){
                    $('#menuContainer').css('display','none')
                })
               
                var contentArr=document.getElementsByClassName('value-pass');
                for(let i=0;i<contentArr.length;i++){
                 
                    var pattern=/<(.*?)>/mg;
                    var showText1=contentArr[i].innerText.match(pattern);
                    console.log(showText1);
                    var showText=contentArr[i].innerText.replace(pattern,'');
                   
                    $('.item-content')[i].innerText = showText;

                }
            });

            $('.menu-item')[0].onclick= function(){
                   $.get('/signout',function(data,status){
                       if(status){
                           window.location.href='http://localhost:3000/signin'
                       }
                   })
            }

              $('.menu-item')[1].onclick= function(){
                   $.get('/posts/create',function(data,status){
                       if(status){
                           window.location.href='http://localhost:3000/posts/create'
                       }
                   })
            }
       